var LOC_MENUBAR = 0;
var LOC_RANDOMVID_MODAL = 1;
var CURRENT_LOCATION = 0;

var weatherOpen = false;

//menu bar listener
addListener(menuBar = function(actionKey, currentLocation){
	if(currentLocation == LOC_MENUBAR){
		switch(actionKey){
			case ACTION_KEYDOWN_LEFT:
			keyLeftMenuBar();
			break;
			case ACTION_KEYDOWN_RIGHT:
			keyRightMenuBar();
			break;
			case ACTION_KEYUP_ENTER:
			keyEnterMenuBar();
			break;
		}
	}
});

//random video modal listener
addListener(randomVideoModal = function(actionKey, currentLocation){
	if(currentLocation == LOC_RANDOMVID_MODAL){
		switch(actionKey){
			case ACTION_KEYUP_ENTER:
			keyEnterRandomModal();
			break;
		}
	}
});

function keyLeftMenuBar(){
	if(menuBarIndex > 0){
		var tmpIndex = menuBarIndex;
		menuBarIndex--;
	}else{
		var tmpIndex = menuBarIndex;
		menuBarIndex = (menuBarItems-1);
	}
	
	an1 = new Animator().addSubject(
	new NumericalStyleSubject(
		"navMenu",
		"margin-left",
		((tmpIndex*-1)*columnWidth),
		((menuBarIndex*-1)*columnWidth))).addSubject(
	new ColorStyleSubject(
		"menuTD"+tmpIndex,
		"color",
		'#FFFFFF',
		'#666666')).addSubject(
	new ColorStyleSubject(
		"menuTD"+menuBarIndex,
		"color",
		'#666666',
		'#FFFFFF'));
	
	an1.toggle();
	
	menuBarMouseIn();
}

function keyRightMenuBar(){
	if(menuBarIndex < (menuBarItems-1)){
		var tmpIndex = menuBarIndex;
		menuBarIndex++;
	}else{
		var tmpIndex = menuBarIndex;
		menuBarIndex = 0;
	}
		
	var an1 = new Animator().addSubject(
	new NumericalStyleSubject(
		"navMenu",
		"margin-left",
		((tmpIndex*-1)*columnWidth),
		((menuBarIndex*-1)*columnWidth))).addSubject(
	new ColorStyleSubject(
		"menuTD"+tmpIndex,
		"color",
		'#FFFFFF',
		'#666666')).addSubject(
	new ColorStyleSubject(
		"menuTD"+menuBarIndex,
		"color",
		'#666666',
		'#FFFFFF'));
	
	an1.toggle();

	menuBarMouseIn();
}

function menuBarMouseIn(){
	var td = $("menuTD"+menuBarIndex);
	var type = td.readAttribute('typeId');

	if(weatherOpen){
		hideWeatherOverlay();
		weatherOpen = false;
	}
	
	if(type == 1){
		movieMouseIn();
	}else if(type == 2){
		tvShowsMouseIn();
	}else if(type == 3){
		musicMouseIn();
	}else if(type == 5){
		weatherOpen = true;
		weatherMouseIn();
	}else if(type == 6){
		randomMouseIn();
	}
}

function keyEnterMenuBar(){
	var td = $("menuTD"+menuBarIndex);
	
	if(td.readAttribute('link') != ''){
		location.href = td.readAttribute('link');
	}else {
		var type = td.readAttribute('typeId');
		if(type == 6){
			keyEnterRandomNavMenuItem();
		}
	}
}

function keyEnterRandomNavMenuItem(){
	//showRandomModal();
	//CURRENT_LOCATION = LOC_RANDOMVID_MODAL;
}

function keyEnterRandomModal(){
	//CURRENT_LOCATION = LOC_MENUBAR;
}